package com.lq.schoolshop.dao;

import com.lq.schoolshop.pojo.Expand.ShopAndGoods;
import com.lq.schoolshop.pojo.ShopCar;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author
 * @Date2021/1/12 16:53
 * @Version V1.0
 * 购物车商品类
 **/
public interface ShopCarMapper {

    //1.查询购物车里面的所有商品
    @Select("SELECT s.id AS id , s.count AS COUNT,g.id AS gid, g.name AS gname,g.count AS gcount,g.price AS gprice,g.image AS gimage,g.detail AS gdetail,st.id AS stid,st.name AS stname FROM shopcar s,goods g,store st WHERE s.gid = g.id AND g.storeid=st.id and uid = #{uid}")
    List<ShopAndGoods>selByAll(@Param("uid") int uid);

    //2添加商品到购物车
    @Insert("INSERT INTO shopcar VALUES(DEFAULT,#{uid},#{gid},#{count},'无')")
    int insertAll(@Param("uid") int uid, @Param("gid") int gid, @Param("count") int count);

    //2.1根据商品ID查询 该商品是否已经存在于购物车中  如果存在 则数量+1  如果不存在 直接添加就行
    @Select("SELECT count(*) FROM shopcar WHERE gid = #{gid}")
    int sqlByGidCount(@Param("gid") int gid);

    //2.3 如果存在 数量+1
    @Update("UPDATE shopcar SET COUNT = COUNT + #{count} WHERE gid = #{gid}")
    int updateGoodsCount(@Param("count") int count,@Param("gid") int gid);

     //3.购物车批量删除
    int deleteorderByAll(int[] array);

    //4.批量查询购物车的商品
    List<ShopAndGoods>selByShopId(int[] id);

    //5.根据商品ID查询 批量查询
    Integer [] selAllById(Integer []id);
}
